import { computed } from 'vue'

/**
 * 是否为开发环境
 */
export const isDev = import.meta.env.DEV

// 获取屏幕边界到安全区域距离
const { safeAreaInsets, statusBarHeight } = uni.getSystemInfoSync()

export const safeTop = computed(() => {
  const result = statusBarHeight || 25

  return { paddingTop: result + 'px' }
})

export const safeBottom = computed(() => {
  let result = 0

  // #ifdef MP-WEIXIN
  result = safeAreaInsets!.bottom
  // #endif

  return { paddingBottom: result + 'px' }
})

/**
 * 页面路径
 */
export enum pageUrl {
  // pages
  'index' = '/pages/index/index',
  'my' = '/pages/my/my',
  'cart' = '/pages/cart/cart',
  'category' = '/pages/category/category',

  // pagesGoods
  'goods-list' = '/pagesGoods/pages/list/list',
  'goods-detail' = '/pagesGoods/pages/goods/goods',
  'goods-evaluate' = '/pagesGoods/pages/evaluate/evaluate',
  'goods-search' = '/pagesGoods/pages/search/search',

  // pagesOrder
  'order-create' = '/pagesOrder/pages/create/create',
  'order-detail' = '/pagesOrder/pages/detail/detail',
  'order-pay' = '/pagesOrder/pages/payment/pay',
  'order-payment' = '/pagesOrder/pages/payment/payment',
  'order-list' = '/pagesOrder/pages/list/list',
  'order-receive' = '/pagesOrder/pages/receive/receive',
  'order-evaluate' = '/pagesOrder/pages/evaluate/evaluate',
  'order-refund' = '/pagesOrder/pages/refund/refund',
  'order-refund-list' = '/pagesOrder/pages/refund/list',
  'order-refund-detail' = '/pagesOrder/pages/refund/detail',
  'order-delivery' = '/pagesOrder/pages/delivery/delivery',
  'order-center' = '/pagesOrder/pages/center/center',
  'recharge-order-list' = '/pagesOrder/pages/recharge/list',

  // pagesMember
  'login' = '/pagesMember/pages/login/login',
  'setting' = '/pagesMember/pages/settings/settings',
  'profile' = '/pagesMember/pages/profile/profile',
  'address' = '/pagesMember/pages/address/address',
  'address-form' = '/pagesMember/pages/address/address-form',
  'balance' = '/pagesMember/pages/balance/balance',
  'balance-recharge' = '/pagesMember/pages/balance/recharge',
  'coupon' = '/pagesMember/pages/coupon/coupon',
  'coupon-center' = '/pagesMember/pages/coupon/center',
  'favorite' = '/pagesMember/pages/favorite/favorite',

  // pagesOther
  'rich-text' = '/pagesOther/pages/blank/rich-text',
}

/** 订单状态枚举 */
export enum orderState {
  /** 待付款 */
  toPay = 1,
  /** 待发货 */
  toSend = 2,
  /** 待收货 */
  toReceived = 3,
  /** 待评价 */
  toEvaluate = 4,
  /** 已完成 */
  completed = 5,
  /** 已取消 */
  canceled = 6,
  /** 申请取消 */
  applyCancel = 7,
}

/*
 * 订单状态列表
 */
export const orderStateList = [
  { id: 0, text: '全部' },
  { id: 1, text: '待付款' },
  { id: 2, text: '待发货' },
  { id: 3, text: '待收货' },
  { id: 4, text: '待评价' },
  { id: 5, text: '已完成' },
  { id: 6, text: '已取消' },
  { id: 7, text: '申请取消' },
]

/** 订单状态操作 */
export const orderStateActions = {
  normalTransaction: [
    orderState.toSend,
    orderState.toReceived,
    orderState.toEvaluate,
    orderState.completed,
  ],
  evaluatable: [orderState.toEvaluate],
  receiveble: [orderState.toReceived],
  cancelable: [orderState.toPay, orderState.toSend],
  deletable: [orderState.toPay, orderState.canceled, orderState.completed],
  refundable: [orderState.toEvaluate, orderState.completed],
}

/* 退款状态枚举 */
export enum refundState {
  /** 退款中 */
  refunding = 2,
  /** 退款成功 */
  refunded = 3,
}

/** 退款状态列表 */
export const refundStateList = [
  { id: 1, text: '取消审核中' },
  { id: 2, text: '退款审核中' },
  { id: 3, text: '退款成功' },
]

/** 订单类型 */
export enum orderType {
  //普通订单
  default = 1,
}

/** 退款类型 */
export enum refundType {
  //退款
  refund = 1,
  //退货退款
  refundAndReturn = 2,
}

export enum smsTemplateCode {
  // 注册
  register = 'user_register',
  // 手机号码认证
  verifyPhone = 'user_mobile_verify',
  // 重置密码
  resetPassword = 'user_retrieve_pwd',
  // 修改手机号码
  changePhone = 'user_change_mobile',
}
